# 洗衣机
class Washer:

    def __init__(self, width, height):
        self.width = width
        self.height = height

    def print_info(self):
        print(f"洗衣机的宽度是{self.width}")
        print(f"洗衣机的高度是{self.height}")

    def __str__(self):
        return '这是海尔洗衣机的说明书'

    def __del__(self):
        print(f"{self}对象已经被删除")


haier1 = Washer(10, 20)
haier2 = Washer(30, 40)
haier1.print_info()
haier2.print_info()


# 烤地瓜
class SweetPotato:
    def __init__(self):
        self.cook_time = 0
        self.cook_static = '生的'
        self.condiments = []

    def cook(self, time):
        """烤地瓜的方法"""
        self.cook_time += time
        if 0 <= self.cook_time < 3:
            self.cook_static = '生的'
        elif 3 <= self.cook_time < 5:
            self.cook_static = '半生不熟'
        elif 5 <= self.cook_time < 8:
            self.cook_static = '熟了'
        elif self.cook_time >= 8:
            self.cook_static = '糊了'

    def add_condiments(self, condiment):
        """添加调料"""
        self.condiments.append(condiment)

    def __str__(self):
        return f"这个地瓜烤了{self.cook_time}分钟，状态是{self.cook_static}，添加的调料有{self.condiments}"


digua1 = SweetPotato()
print(digua1)

digua1.cook(2)
digua1.add_condiments('酱油')
print(digua1)

digua1.cook(2)
digua1.add_condiments('辣椒面儿')
print(digua1)


# 房子类、家具类
class Furniture:
    def __init__(self, name, area):
        self.name = name
        self.area = area


class Home:
    def __init__(self, address, area):
        self.address = address
        self.area = area
        self.free_area = area
        self.furniture = []

    def __str__(self):
        return f'房子坐落于{self.address},占地面积{self.area},家具有{self.furniture}'

    def add_furniture(self, item):
        """容纳家具"""
        if self.free_area >= item.area:
            self.furniture.append(item.name)
            self.free_area -= item.area
        else:
            print("家具太大，无法容纳")


bed = Furniture("双人床", 6)
home1 = Home('北京', 1200)
print(home1)

home1.add_furniture(bed)
print(home1)

sofa = Furniture('沙发', 10)
home1.add_furniture(sofa)
print(home1)

ball = Furniture('篮球场', 1500)
home1.add_furniture(ball)
print(home1)


# 小明小美爱跑步，小明75公斤重，小美45公斤重，每次跑步减重0.5公斤，吃饭增重1公斤
class Person:
    def __init__(self, name, weight):
        self.name = name
        self.weight = weight

    def __str__(self):
        return f"{self.name}体重{self.weight}公斤,很爱跑步"

    def run(self):
        print(f"{self.name}在跑步，体重减少0.5公斤")
        self.weight -= 0.5

    def eat(self):
        print(f"{self.name}在吃饭，体重增加1公斤")
        self.weight += 1


xiaoming = Person('小明', 75)
print(xiaoming)
xiaoming.eat()
xiaoming.run()
print(xiaoming)

xiaomei = Person('小美', 45)
print(xiaomei)
xiaomei.eat()
xiaomei.run()
print(xiaomei)
